package com.wxg.jbrowser;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import com.machinepublishers.jbrowserdriver.JBrowserDriver;
import com.wxg.utils.My;
import com.wxg.utils.MyJBrowserDriver;

/**
 * date: 2018年2月8日
 * - 发现"jbrowserdriver-1.0.0-RC1"的问题
 * -	* 1) 如果有link的css style获取不到会抛出大串异常
 * -	* 2) `ele.getSize()`报错,`org.openqa.selenium.ElementNotVisibleException: Element is not visible.`
 * - 综上,"phantomjsdriver"仍然是首选
 * 
 * 
 * @author Wxg
 *
 */
public class Demo101 {
	public static void closeDriver(){
		new MyJBrowserDriver().closeDriver();
	}
	public static void main(String[] args) {
		code102();
		
		
		closeDriver();
	}
	
	
	public static void code102(){
		WebDriver driver = new MyJBrowserDriver().getDriver();
		String url = My.fileUrl("D:/wxg/UeHtmlStore/html_101.html");
		driver.get(url);
//		System.out.println(driver.getPageSource());
		List<WebElement> list = driver.findElements(By.tagName("*"));

		String[] exceptArr = {"tbody", "tr", "td"};
		
		if (null != list) {
			for (WebElement ele : list) {
				System.out.printf( "\ndisplay: %s, tagName: %s", ele.getAttribute("display"), ele.getTagName() );
//				if(ele.getAttribute("display"))
				if(My.notIn(ele.getTagName(), exceptArr)){
					Dimension d = ele.getSize();
					Point p = ele.getLocation();
					System.out.printf("\nx: %s, y: %s, width: %s, height: %s\n", p.x, p.y, d.width, d.height);
				}
			}
		}
	}
	
	
	/**
	 * get : www.baidu.com
	 */
	public static void code101(){
		MyJBrowserDriver myDriver = new MyJBrowserDriver();
		WebDriver driver = myDriver.getDriver();
		driver.get("https://www.baidu.com/");
		System.out.println( ((JBrowserDriver)driver).getStatusCode() );
		System.out.println(driver.getPageSource());
	}
}
